package com.music.server.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.music.server.pojo.Comment;
import com.music.server.service.CommentService;
import com.music.server.utils.ResultVo;
import com.music.server.vo.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *  歌单、歌曲评论管理
 * @author testjava
 * @since 2021-03-07
 */
@RestController
@RequestMapping("comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 添加歌单、歌曲评论信息
     * @return
     */
    @PostMapping("save")
    public ResultVo save(@RequestBody Comment comment){
        comment.setCreateTime(new Date());
        boolean save = commentService.save(comment);
        if (save) return ResultVo.ok();
        return ResultVo.error();
    }



    /**
     * 分页查询所有的歌单、歌曲评论信息
     * @return
     */
    @PostMapping("page/{pageNum}/{size}")
    public ResultVo page(@PathVariable Integer pageNum, @PathVariable Integer size, @RequestBody CommentVo CommentVo){

        return ResultVo.ok().data("page",commentService.page(pageNum,size,CommentVo));
    }

    /**
     * 删除歌单、歌曲评论信息
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public ResultVo delete(@PathVariable Integer id){
        boolean delete = commentService.removeById(id);
        if (delete) return ResultVo.ok();
        return ResultVo.error();
    }



}

